package com.example.controller;


import com.example.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/redis")
public class RedisConntrller {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("get/{key}")
    public Result get(@PathVariable("key") String key){
        String value = (String) redisTemplate.opsForValue().get(key);
        return Result.success(value);
    }

    @PostMapping("set/{key}/{value}")
    public Result set(@PathVariable("key") String key,
                      @PathVariable("value")String value){
        redisTemplate.opsForValue().set(key, value);

        return Result.success();
    }
}
